import { ApiProperty } from "@nestjs/swagger";
import { Type } from "class-transformer";
import {
  IsArray,
  IsNumber,
  IsNumberString,
  IsOptional,
  IsString,
  Min,
  ValidateNested,
} from "class-validator";

export class CreateOrderItemDto {
  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "客户PO(客户自己决定的商品ID), 如无为空",
  })
  po?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "客方货号(客户方面的送货编号), 如无为空",
  })
  no?: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "备注",
  })
  remark?: string;

  /** 键值uuid */
  @IsString()
  @ApiProperty({
    description: "商品类型ID",
  })
  type: string;

  /** 键值uuid */
  @IsString()
  @ApiProperty({
    description: "商品质量ID",
  })
  quality: string;

  @IsString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "尺寸",
  })
  size?: string;

  @IsNumberString()
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "价格",
  })
  price?: string;

  @IsNumber()
  @Min(1)
  @IsOptional()
  @ApiProperty({
    required: false,
    description: "数量",
  })
  quantity: number;
}

export class CreateOrderArrayDto {
  @IsString()
  @ApiProperty({
    description: "客户ID",
  })
  clientId: string;

  @ValidateNested({ each: true })
  @IsArray()
  @Type(() => CreateOrderItemDto)
  @ApiProperty({ description: "订单项", type: [CreateOrderItemDto] })
  orders: CreateOrderItemDto[];
}
